
package com.flowmodule.servlet;
import com.flowmodule.bean.TbFlowFlowNodeMiddle;
import com.flowmodule.dao.*;
import com.usersmodule.bean.TbUsers;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbFlowFlowNodeMiddleServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        int userId=((TbUsers) request.getSession().getAttribute("Users")).getUserId();        
        if("add".equals(method)){
        int flowFlowNodeMiddleSeq=Integer.parseInt(request.getParameter("flowFlowNodeMiddleSeq"));
        int flowId=Integer.parseInt(request.getParameter("flowId"));
        int flowNodeId=Integer.parseInt(request.getParameter("flowNodeId"));
            if(new TbFlowFlowNodeMiddleDAO().add(new TbFlowFlowNodeMiddle(flowFlowNodeMiddleSeq,flowId,flowNodeId,userId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_FlowFlowNodeMiddle", "FlowFlowNodeMiddleId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int flowFlowNodeMiddleId=Integer.parseInt(request.getParameter("flowFlowNodeMiddleId"));
        int flowFlowNodeMiddleSeq=Integer.parseInt(request.getParameter("flowFlowNodeMiddleSeq"));
        int flowId=Integer.parseInt(request.getParameter("flowId"));
        int flowNodeId=Integer.parseInt(request.getParameter("flowNodeId"));
            if(new TbFlowFlowNodeMiddleDAO().edit(new TbFlowFlowNodeMiddle(flowFlowNodeMiddleId,flowFlowNodeMiddleSeq,flowId,flowNodeId,userId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response);
        if ("listById".equals(method)) {
            request.getSession(true).setAttribute("tbFlowFlowNodeMiddle",new TbFlowFlowNodeMiddleDAO().getTbFlowFlowNodeMiddleByFlowFlowNodeMiddleId(Integer.parseInt(request.getParameter("flowFlowNodeMiddleId"))));
            response.sendRedirect("FlowModule/TbFlowFlowNodeMiddleOperate.jsp");
    	}
        if ("listByFlowId".equals(method)) {
        	request.getSession(true).setAttribute("tbFlowList",new TbFlowDAO().getTbFlowAll());
        	request.getSession(true).setAttribute("tbFlowNodeList",new TbFlowNodeDAO().getTbFlowNodeAll());
        	request.getSession(true).setAttribute("tbFlowFlowNodeMiddleList",new TbFlowFlowNodeMiddleDAO().getTbFlowFlowNodeMiddleByFlowId(Integer.parseInt(request.getParameter("flowId"))));
            response.sendRedirect("FlowModule/TbFlowFlowNodeMiddleList.jsp?flowId="+request.getParameter("flowId"));
    	}
        if("showadd".equals(method)){
        	request.getSession(true).setAttribute("tbFlowList",new TbFlowDAO().getTbFlowAll());
        	request.getSession(true).setAttribute("tbFlowNodeList",new TbFlowNodeDAO().getTbFlowNodeAll());
            request.getSession(true).removeAttribute("tbFlowFlowNodeMiddle");
            response.sendRedirect("FlowModule/TbFlowFlowNodeMiddleOperate.jsp?flowId="+request.getParameter("flowId"));
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbFlowFlowNodeMiddleList",new TbFlowFlowNodeMiddleDAO().getTbFlowFlowNodeMiddleByFlowId(Integer.parseInt(request.getParameter("flowId"))));
        response.sendRedirect("FlowModule/TbFlowFlowNodeMiddleList.jsp?flowId="+request.getParameter("flowId"));
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
